package array;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Author wsyjiamian@163.com
 * @Description 数组的定义
 * @Date 2020/8/19 16:39
 */

public class MyArray {

    public static void main(String[] args) {
        MyArray ma = new MyArray();
        ma.copyCreateArray();
    }

    // 静态方式创建数据
    void staticCreateArray(){
        int[] arr = new int[10];
    }

    //动态方式创建
    void dynamicCreateArray(){
        Object obj = Array.newInstance(int.class , 4);
        Array.setInt(obj , 0 , 1);
        Array.setInt(obj , 1 , 2);
        Array.setInt(obj , 2 , 3);
        Array.setInt(obj , 3 , 4);
        System.out.println(Array.getLength(obj));
    }

    //从已有数组中进行拷贝
    void copyCreateArray(){
        int []arr = {1,2,3,4};
        int[] arr0 = Arrays.copyOf(arr ,2);
        int[] arr1 = new int[3];
        System.arraycopy(arr , 0 , arr1 , 0 , 3);
    }

}
